package agents;

import agents.participantagentbehaviours.RegisterAuctionParticipantServiceBehaviour;
import jade.core.Agent;
import jade.core.Location;
import jade.core.behaviours.OneShotBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;

public class ParticipantAgent extends Agent {
	Location agentLocation;
	@Override
	protected void setup() {
		addBehaviour(new CloneAgentToSameContainerBehaviour());
		addBehaviour(new RegisterAuctionParticipantServiceBehaviour(this));
	}
	
	class RegisterAuctionParticipantService extends OneShotBehaviour{

		@Override
		public void action() {
			DFAgentDescription dfd = new DFAgentDescription();
	        dfd.setName(myAgent.getAID());
	        
	        ServiceDescription service = new ServiceDescription();
	        service.setName("auctionParticipant: " + myAgent.getLocalName());
	        service.setType("auctionParticipant");
	        dfd.addServices(service);
	        try {
				DFService.register(myAgent, dfd);
			} catch (FIPAException e) {
				throw new RuntimeException(e);
			}
		}
	}
	
	class CloneAgentToSameContainerBehaviour extends OneShotBehaviour{

		@Override
		public void action() {
			doClone(here(), ParticipantAgent.this.getLocalName() + "-Clone");
		}
	}
}
